from wordpress_project.base.base_page import Tools
import time
from selenium import webdriver


class register_tool(Tools):
    register_url = "http://192.168.0.125:9009/wp-login.php"  # 网址
    r_username_ele = '[name="user_login"]'  # 用户名css定位
    email_ele = '[name="user_email"]'  # 电子邮箱css定位
    r_register_ele = '[name="wp-submit"]'  # 注册按钮css定位
    q_register_ele = '[id="nav"] a'
    register_success_ele = '[class="message"]'  # 注册成功 之后的断言定位
    register_fail_ele = '[id="login_error"]'  # 注册失败之后断言定位

    def register_action(self, rue, em):
        self.visit(self.register_url)
        # 在方法中，调用同一个类的其他方法   self.方法名  在方法中，调用类的变量   self.变量名
        self.by_css(self.q_register_ele).click()
        time.sleep(1)
        self.by_css(self.r_username_ele).send_keys(rue)
        time.sleep(1)
        self.by_css(self.email_ele).send_keys(em)
        time.sleep(1)
        self.by_css(self.r_register_ele).click()
        self.img()  # 调用截图

    def get_success_msg(self):
        return self.by_css(self.register_success_ele).text

    def get_fail_msg(self):
        return self.by_css(self.register_fail_ele).text

# b = webdriver.Chrome()
# c = register_tool(driver=b)
# c.visit(c.register_url)
# c.register_action(rue='xiaoxiao1', em='123xxn@qq.com')
# time.sleep(5)
# c.quit()
